package com.banmao.algorithm.No201To300.No209;

public class Solution1 {

    public static int minSubArrayLen(int target, int[] nums) {

        int left = 0; // 左边界
        int right = 0; // 右边界
        int sum = 0; // 和
        int length = Integer.MAX_VALUE; // 子数组长度

        for (; right < (nums.length); right++) {
            sum += nums[right];
            if(sum < target) {
                continue;
            }
            while(sum >= target) {
                int tempLength = right - left + 1;
                length = Math.min(length, tempLength);
                sum -= nums[left];
                left++;

            }
        }
        return length == Integer.MAX_VALUE ? 0 : length;

    }

}
